home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17967 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Question about abstract base class
  5. Date: Thu, 18 Apr 1996 09:35:23 +0200
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <3175F0BB.446B9B3D@intellektik.informatik.th-darmstadt.de>
  8. References: <4l3u1s$j80@hermes.acs.unt.edu>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Chen-five Chi wrote:
  16. > I just wrote a simple program like this:
  17. > class shape
  18. > {
  19. >    public:
  20. >         virtual void print() const = 0;
  21. > ........
  22. > }
  23. > clase TwoDimensionObject: public shape
  24. > {
  25. >    public:
  26. >         virtual void area() const = 0;
  27. > ...
  28. > }
  29. > class Square: public TwoDimensionObject
  30. > {
  31. >    private:
  32. >         int side;
  33. >    public:
  34. >         virtual void area()
  35. >         {
  36. >            cout << "Square area: " << (side * side);
  37. >         }
  38. > }
  39. > ...
  40. > void main()
  41. > {
  42. >         Square s1;
  43. > ....
  44. > }
  45. > ==============================
  46. > And I get a compiler error in BC 4.51 said "s1 is abstract base class...."
  47. > After I move the keyword "const", the program runs normally without any
  48. > problem.
  49. > I would like to know
  50. > "Why I Could not put 'const' in the ABC? and the different these two?
  51. > Your kindness help is appreciated.
  52.  
  53. If you declare a pure virtual member-function as const in some
  54. class, you've to provide an implementation for a function with
  55. o the same name
  56. o the same arguments
  57. o the same qualifier (i.e. the function also has to be const-
  58.                       qualified).
  59. in some subclass.
  60. Therefore your problem should disappear when you declare
  61. 'Square::area' as const (and provide an implementation for the
  62. 'print' member-function).
  63.  
  64.     Enno
  65.